﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DBWTProject.route;
using System.Globalization;

namespace DBWTProject.models
{
    public class Route
    {
        public int ID { get; set; }
        public User User { get; set; }
        public DateTime Date { get; set; }
        public string Name { get; set; }
        public string RawKML { get; set; }

        public double Distance
        {
            get
            {
                KmlParser parser = new KmlParser(RawKML);
                IList<double> totalDistance = parser.GetDistanceDifference();
                
                if(totalDistance == null)
                {
                    return Double.NaN;
                }

                return totalDistance.Sum();
            }
        }
        public double Elevation
        {
            get
            {
                KmlParser parser = new KmlParser(RawKML);
                IList<double> totalElevation = parser.GetElevationDifference();

                if (totalElevation == null)
                {
                    return Double.NaN;
                }

                return totalElevation.Sum();
            }
        }
        public TimeSpan Duration
        {
            get
            {
                KmlParser parser = new KmlParser(RawKML);
                TimeSpan duration = parser.GetDuration();
                return duration;
            }
        }

        //Mit TimeSpan lässt sich schlecht Arbeiten: a) Formattierung b) Google braucht double
        public double DurationInHours
        {
            get
            {
                return Duration.TotalHours;
        //        //TimeSpan duration = Duration;
        //        //int hours = duration.Hours;
        //        //double minutes = duration.Minutes / 60.0; //0,5 statt 30
        //        //return hours + minutes;
            }
        }

        public double MeanSpeed
        {
            get
            {
                KmlParser parser = new KmlParser(RawKML);
                double meanSpeed = parser.GetMeanSpeed();
                return meanSpeed;
            }
        }
    }
}